home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / xpcom / xpt_arena.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  4KB  |  135 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. /*
  39.  * Simple arena allocator for xpt (which avoids using NSPR).
  40.  */
  41.  
  42. #ifndef __xpt_arena_h__
  43. #define __xpt_arena_h__
  44.  
  45. #include "prtypes.h"
  46. #include <stdlib.h>
  47.  
  48.  
  49. /*
  50.  * The linkage of XPT API functions differs depending on whether the file is
  51.  * used within the XPT library or not.  Any source file within the XPT
  52.  * library should define EXPORT_XPT_API whereas any client of the library
  53.  * should not.
  54.  */
  55. #ifdef EXPORT_XPT_API
  56. #define XPT_PUBLIC_API(t)    PR_IMPLEMENT(t)
  57. #define XPT_PUBLIC_DATA(t)   PR_IMPLEMENT_DATA(t)
  58. #else
  59. #ifdef _WIN32
  60. #    define XPT_PUBLIC_API(t)    __declspec(dllimport) t
  61. #    define XPT_PUBLIC_DATA(t)   __declspec(dllimport) t
  62. #else
  63. #    define XPT_PUBLIC_API(t)    PR_IMPLEMENT(t)
  64. #    define XPT_PUBLIC_DATA(t)   t
  65. #endif
  66. #endif
  67. #define XPT_FRIEND_API(t)    XPT_PUBLIC_API(t)
  68. #define XPT_FRIEND_DATA(t)   XPT_PUBLIC_DATA(t)
  69.  
  70. PR_BEGIN_EXTERN_C
  71.  
  72. /*
  73.  * Simple Arena support. Use with caution!
  74.  */ 
  75.  
  76. typedef struct XPTArena XPTArena;
  77.  
  78. XPT_PUBLIC_API(XPTArena *)
  79. XPT_NewArena(PRUint32 block_size, size_t alignment, const char* name);
  80.  
  81. XPT_PUBLIC_API(void)
  82. XPT_DestroyArena(XPTArena *arena);
  83.  
  84. XPT_PUBLIC_API(void)
  85. XPT_DumpStats(XPTArena *arena);
  86.  
  87. XPT_PUBLIC_API(void *)
  88. XPT_ArenaMalloc(XPTArena *arena, size_t size);
  89.  
  90. XPT_PUBLIC_API(char *)
  91. XPT_ArenaStrDup(XPTArena *arena, const char * s);
  92.  
  93. XPT_PUBLIC_API(void)
  94. XPT_NotifyDoneLoading(XPTArena *arena);
  95.  
  96. XPT_PUBLIC_API(void)
  97. XPT_ArenaFree(XPTArena *arena, void* block);
  98.  
  99. /* --------------------------------------------------------- */
  100.  
  101. #define XPT_MALLOC(_arena, _bytes) \
  102.     XPT_ArenaMalloc((_arena), (_bytes))
  103.  
  104. #ifdef DEBUG
  105. #define XPT_FREE(_arena, _ptr) \
  106.     XPT_ArenaFree((_arena), (_ptr))
  107. #else
  108. #define XPT_FREE(_arena, _ptr) \
  109.     ((void)0)
  110. #endif
  111.  
  112. #define XPT_STRDUP(_arena, _s) \
  113.     XPT_ArenaStrDup((_arena), (_s))
  114.  
  115. #define XPT_CALLOC(_arena, _size) XPT_MALLOC((_arena), (_size))
  116. #define XPT_NEW(_arena, _struct) ((_struct *) XPT_MALLOC((_arena), sizeof(_struct)))
  117. #define XPT_NEWZAP(_arena, _struct) XPT_NEW((_arena), _struct)
  118. #define XPT_DELETE(_arena, _ptr) do{XPT_FREE((_arena), (_ptr)); ((_ptr)) = NULL;}while(0)
  119. #define XPT_FREEIF(_arena, _ptr) do{if ((_ptr)) XPT_FREE((_arena), (_ptr));}while(0)
  120.  
  121. /* --------------------------------------------------------- */
  122.  
  123. #ifdef DEBUG
  124. XPT_PUBLIC_API(void)
  125. XPT_AssertFailed(const char *s, const char *file, PRUint32 lineno);
  126. #define XPT_ASSERT(_expr) \
  127.     ((_expr)?((void)0):XPT_AssertFailed(# _expr, __FILE__, __LINE__))
  128. #else
  129. #define XPT_ASSERT(_expr) ((void)0)
  130. #endif
  131.  
  132. PR_END_EXTERN_C
  133.  
  134. #endif /* __xpt_arena_h__ */
  135.